package Chuong07;

import java.io.*;

public class Bai07 {

	BufferedReader in = new BufferedReader(new InputStreamReader(System.in));	
	private static FileReader fR;
	private static FileWriter fW;
	private static BufferedReader bR;
	private static BufferedWriter bW;
	
	String filename = "D:/Hoc Tap/Hoc Ki VII/Chuyen De Java/OnTap_Code/OnTap/src/Chuong07/File/matran.dat";
	//String filename = "Z:/matran.dat";
	
	int m, n;
	int[][] A;
	
	public Bai07(){
		try {
			do{
				System.out.print("Số dòng: "); 
				this.m = Integer.parseInt(in.readLine());
			}while(this.m < 1);
			
			do{
				System.out.print("Số cột: "); 
				this.n = Integer.parseInt(in.readLine());
			}while(this.n < 1);	
			//A = new int[m][n];
			Write_MaTran();
			Read_MaTran();
			
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void Write_MaTran(){
		try {
			fW = new FileWriter(filename);
			bW = new BufferedWriter(fW);
			bW.write(m+"");bW.newLine();
			bW.write(n+"");bW.newLine();
			for (int i = 0; i < m; i++){
				for(int j = 0; j < n; j++){
					System.out.print("A[" + (i + 1) + "][" + (j + 1) + "] = "); 
					int pt = Integer.parseInt(in.readLine());
					bW.write(pt + "\t");
				}
				bW.newLine();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} 
		catch (IOException e) {
			e.printStackTrace();
		}
		try { 
			bW.flush();
			bW.close(); 
			fW.close();	
		} 
		catch (IOException e) { 
			e.printStackTrace();
		}
	}
	
	public void Read_MaTran(){
		try {
			fR = new FileReader(filename);
			bR = new BufferedReader(fR);
			int i = bR.read();
			while (i != -1) {
				System.out.print((char) i);
				i = bR.read();
			};
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		try { 
			fR.close(); 
			bR.close();
		} 
		catch (IOException e) { 
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		new Bai07();
	}

}
